﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SmartSpace.Core;

namespace SsTool.Core.Windows
{
    /// <summary>
    /// Interaction logic for OrgWindow.xaml
    /// </summary>
    public partial class OrgWindow : Window
    {
        public Org Org { get; private set; }

        public OrgWindow(Org org, bool isParent)
        {
            InitializeComponent();

            if (isParent)
            {
                Org = new Org();
                Org.Id = Guid.NewGuid();
                if (org != null)
                {
                    Org.Code = org.Code;
                    //Org.Parent = org;
                    Org.ParentId = org.Id;
                }
            }
            else
            {
                Org = org;
            }
            this.DataContext = Org;
        }

        private void _ctlBtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            ICoreService service = App.Get<ICoreService>();
            Org.Type = _ctlListType.SelectedIndex + 1;
            if (service.SaveOrg(Org))
            {
                DialogResult = true;
            }
        }

        private void _ctlBtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
